package com.shijunhao.graduation.domain.bean;

import org.springframework.http.HttpStatus;

import java.io.Serializable;

/**
 * @author: shijunhao
 * @date: 2022/3/2 22:49
 * @description: 结果状态返回
 */
public class ResultCode<T> implements Serializable {

    public static final long serialVersionUID = 1L;

    private Integer code;

    private String msg;

    private T data;

    public ResultCode() {
    }

    public ResultCode(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public ResultCode(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }



    /**
     * @param msg: 消息
     * @param data: 数据
     * @return: com.shijunhao.graduation.domain.bean.ResultCode<T>
     * @author: shijunhao
     * @date: 2022/3/2 22:55
     * @description: 200 状态正常
     */
    public static <T> ResultCode<T> success(String msg,T data){
        return new ResultCode<>(HttpStatus.OK.value(),msg,data);
    }

    /**
     * @param msg: 消息
     * @param data: 数据
     * @return: com.shijunhao.graduation.domain.bean.ResultCode<T>
     * @author: shijunhao
     * @date: 2022/3/2 22:55
     * @description: 500 服务器异常
     */
    public static <T> ResultCode<T> error(String msg,T data){
        return new ResultCode<>(HttpStatus.INTERNAL_SERVER_ERROR.value(),msg,data);
    }

    /**
     * @param msg: 消息
     * @param data: 数据
     * @return: com.shijunhao.graduation.domain.bean.ResultCode<T>
     * @author: shijunhao
     * @date: 2022/3/2 22:55
     * @description: 400 错误请求
     */
    public static <T> ResultCode<T> badRequest(String msg,T data){
        return new ResultCode<>(HttpStatus.BAD_REQUEST.value(),msg,data);
    }

    /**
     * @param code: 状态码
     * @param msg: 消息
     * @param data: 数据
     * @return: com.shijunhao.graduation.domain.bean.ResultCode<T>
     * @author: shijunhao
     * @date: 2022/3/2 23:00
     * @description:
     */
    public static <T> ResultCode<T> resultCode(int code,String msg,T data){
        return new ResultCode<>(code,msg,data);
    }

    public static <T> ResultCode<T> resultCode(int code){
        return resultCode(code,null,null);
    }

    public static <T> ResultCode<T> resultCode(int code,String msg){
        return resultCode(code,msg,null);
    }

    public static <T> ResultCode<T> success(){
        return success(null,null);
    }


    public static <T> ResultCode<T> success(String msg){
        return success(msg,null);
    }

    public static <T> ResultCode<T> success(T data){
        return success(null,data);
    }

    public static <T> ResultCode<T> error(String msg){
        return error(msg,null);
    }

    public static <T> ResultCode<T> error(){
        return error(null,null);
    }

    public static <T> ResultCode<T> error(T data){
        return error(null,data);
    }

    public static <T> ResultCode<T> badRequest(String msg){
        return badRequest(msg,null);
    }

    public static <T> ResultCode<T> badRequest(){
        return badRequest(null,null);
    }

    public static <T> ResultCode<T> badRequest(T data){
        return badRequest(null,data);
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
